package com.xiaoy.dao;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;

/*
 * 辅助类
 */
public class HibernateUtils {
	
	// 得到链接
	private static Configuration cf = new AnnotationConfiguration().configure();
	//private static Configuration cf = new Configuration().configure();
	// 建立工厂
	private static SessionFactory seesionFactory = cf.buildSessionFactory();
	
	public static SessionFactory getSessionFactory () {
		return seesionFactory;
	}
	
	public static Session getSession () {
		return seesionFactory.openSession();
	}
	
	public static void close (Session session) {
		if (session !=null) {
			if (session.isOpen()) {
				session.close();
				session = null;
			}
		}
	}
}
